package com.yhn.init.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.hardware.HardwareAddRequest;
import com.yhn.init.model.dto.hardware.HardwareQueryRequest;
import com.yhn.init.model.dto.hardware.HardwareUpdateRequest;
import com.yhn.init.model.vo.HardwareVO;
import com.yhn.init.service.HardwareService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 五金信息
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/hardware")
public class HardwareController {

    @Resource
    private HardwareService hardwareService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/hardware/list")
    public BaseResponse<Page<HardwareVO>> listByPage(@RequestBody HardwareQueryRequest hardwareQueryRequest) {
        Page<HardwareVO> page = hardwareService.queryPage(hardwareQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/hardware/info")
    public BaseResponse<HardwareVO> getInfoById(@PathVariable("id") Long id) {
        HardwareVO hardware = hardwareService.getInfoById(id);

        return ResultUtils.success(hardware);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/hardware/save")
    public BaseResponse<Long> save(@RequestBody HardwareAddRequest hardwareAddRequest) {
        Long newId = hardwareService.saveHardware(hardwareAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/hardware/update")
    public BaseResponse<Boolean> update(@RequestBody HardwareUpdateRequest hardwareUpdateRequest) {
        boolean result = hardwareService.updateHardware(hardwareUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/hardware/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = hardwareService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/hardware/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = hardwareService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
